package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.ChildrenFrom;
import com.moss.cloud.base.api.model.from.RegionFrom;
import com.moss.cloud.base.api.model.param.RegionTreeParam;
import com.moss.cloud.base.biz.service.ISysProvincesService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(ServiceList.BASE + "/sysProvinces")
public class SysProvincesController {

    private ISysProvincesService sysProvincesService;
    public SysProvincesController(ISysProvincesService sysProvincesService){
        this.sysProvincesService = sysProvincesService;
    }
    /**
     * 行政区域缓存初始化
     *
     * @return
     */
    @PostMapping("/loadProvinces")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "行政区域缓存初始化")
    public Result<?> loadProvinces(){
        return Result.success(sysProvincesService.loadProvinces());
    }

    /**
     * 查询行政区划数据
     *
     * @return
     */
    @PostMapping("/regionTrees")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "查询行政区划数据")
    public Result<?> regionTrees(){
        return Result.success(sysProvincesService.regionTrees());
    }

    /**
     * 查询行政区划数据列表
     *
     * @return
     */
    @PostMapping("/regionPageTree")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "查询行政区划数据列表")
    public Result<?> regionPageTree(@RequestBody RegionTreeParam param){
        return Result.success(sysProvincesService.regionPageTree(param));
    }

    /**
     * 查询行政区子集数据查询
     *
     * @param childrenFrom
     * @return
     */
    @PostMapping("/regionChildren")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "查询行政区子集数据查询")
    public Result<?> regionChildren(@RequestBody @Validated ChildrenFrom childrenFrom){
        return Result.success(sysProvincesService.regionChildren(childrenFrom));
    }

    /**
     * 新增行政区划
     *
     * @param regionFrom
     * @return
     */
    @PostMapping("/saveRegion")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "新增行政区划")
    public Result<?> saveRegion(@RequestBody @Validated RegionFrom regionFrom){
        return Result.success(sysProvincesService.saveRegion(regionFrom));
    }

    /**
     * 编辑行政区划
     *
     * @param regionFrom
     * @return
     */
    @PostMapping("/updateRegion")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "编辑行政区划")
    public Result<?> updateRegion(@RequestBody @Validated RegionFrom regionFrom){
        return Result.success(sysProvincesService.updateRegion(regionFrom));
    }

    /**
     * 删除行政区划
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/removeRegion")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除行政区划")
    public Result<?> removeRegion(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysProvincesService.removeRegion(baseFrom));
    }
}
